package com.litree.service.utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class ReturnMSGUtils {
	/**
	 * send MSG
	 * @param response
	 * @param msg
	 * @param code
	 * @param desc
	 * @throws IOException
	 */
	public static void sentMsg(HttpServletResponse response,Object msg,int code,String desc,String key,Object dataList) throws IOException{
		Map reslutMap = new HashMap();
		reslutMap.put("result", msg);
		reslutMap.put(key, dataList);
		reslutMap.put("code", code);
		reslutMap.put("msg", desc);
		response.getWriter().write(JSON.toJSONString(reslutMap));
	}
	
	/**
	 * send MSG
	 * @param response
	 * @param msg
	 * @param code
	 * @param desc
	 * @throws IOException
	 */
	public static void sentMsg(HttpServletResponse response,Object msg,int code,String desc) throws IOException{
		Map reslutMap = new HashMap();
		reslutMap.put("result", msg);
		reslutMap.put("code", code);
		reslutMap.put("msg", desc);
		response.getWriter().write(JSON.toJSONString(reslutMap));
	}

	/**
	 * send MSG
	 * @param response
	 * @param msg
	 * @param code
	 * @param desc
	 * @throws IOException
	 */
	public static void sentMsgWithCause(HttpServletResponse response,String msg,int code,String desc,String cause) throws IOException{
		Map reslutMap = new HashMap();
		reslutMap.put("msg", msg);
		reslutMap.put("code", code);
		reslutMap.put("error", desc);
		reslutMap.put("cause", cause);
		response.getWriter().write(JSON.toJSONString(reslutMap));
	}
	
	/**
	 * send MSG
	 * @param response
	 * @param msg
	 * @param code
	 * @param desc
	 * @throws IOException
	 */
	public static void sentMsg(HttpServletResponse response,Object msg,int code,String desc,String key,Object dataList,String key2, Object obj) throws IOException{
		Map reslutMap = new HashMap();
		reslutMap.put("result", msg);
		reslutMap.put(key, dataList);
		reslutMap.put(key2, obj);
		reslutMap.put("code", code);
		reslutMap.put("msg", desc);
		response.getWriter().write(JSON.toJSONString(reslutMap,JSONProxy.SYSTEM_FEATURE));
	}
}
